/**
 * 17.指针和字符串 https://www.bilibili.com/video/BV1vs411n7TH?p=75
 */
#include <stdio.h>

void pointer_edit_error();
void pointer_array();

int main() {
    //1.指针修改错误
    pointer_edit_error();
    //2.指针数组
    pointer_array();
}

//1.指针修改错误
void pointer_edit_error() {
    //栈区 字符串
//    char ch[] = "Hello World!";
    /**
     * 数据区 下方的 常量区 字符串, (常量, 只读, 不允许修改)
     * 字符串常量以'\0'结尾!!!★★★
     */
    char *ch = "Hello World!";
    char *ch1 = "Hello World!";
    /**
     * 会报错: Process finished with exit code -1073741819 (0xC0000005)
     * Visual Sudio调试会报错: 写入访问权限冲突
     * 原因  : (常量, 只读, 不允许修改)
     */
//    ch[2] = 'm';
//    *(ch + 2) = 'm';

    printf("1.ch = %p, ch1 = %p\n", ch, ch1); //常量区, ch&ch1 都在同一个地址

}

//2.指针数组
void pointer_array() {
    char *ch = "Hello World!";
    char *ch2 = "你好世界";
    char *strArr[] = {ch, ch2};
    for (int i = 0; i < sizeof(strArr) / sizeof(strArr[0]); ++i) {
        printf("strArr[%d] = %s ", i, strArr[i]);
    }
    puts("");
}
